package com.newcoder.huawei;

import java.util.*;

public class AB1 {

    private static Stack<Integer> stack = new Stack<>();

    public static void main(String... args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.nextLine());//获取总的操作次数
        while (scan.hasNextLine()) {//获取每一次操作
            String str = scan.nextLine();
            String arr[] = str.split(" ");
            if (arr[0].equals("push")) {
                stack.push(Integer.parseInt(arr[1]));
            } else if (arr[0].equals("pop")) {
                pop();
            } else {
                top();
            }
        }
        scan.close();
    }

    public static void pop() {
        if (!stack.isEmpty()) {
            System.out.println(stack.pop());
        }else {
            System.out.println("error");
        }
    }

    public static void top() {
        if (!stack.isEmpty()) {
            System.out.println(stack.peek());
        }else {
            System.out.println("error");
        }
    }
} 